<?php
namespace Suggest\Controller;
use Admin\Controller\AdminbaseController;
class TiyanController extends AdminbaseController {
	
	protected $m;
	
	function _initialize() {
		parent::_initialize();
		$this->m = D('YgclTiyan');
	}
	
	public function index(){
		if(!$_GET['status']){
			$_GET['status'] = 0;
		}
		$this->assign('role',$this->curUser['role']);
		$this->display();
	}
	
	public function del(){
		$id = array_unique((array)I('ids',0));
		if ( empty($id) ) {
			$this->error('请选择要操作的数据!');
		}
		$map = array('id' => array('in', $id));
		$info = $this->m->where($map)->find();
		if($this->m->where($map)->delete()){
			$this->success('删除成功',U('index'));
		} else {
			$this->error('删除失败！');
		}
	}
	
	public function changestatus(){
		$data[$this->m->getPk()] = $_REQUEST['id'];
		$data['status'] = $_REQUEST['status'];
		$data['update_time'] = date('Y-m-d H:i:s');
		if($this->m->save($data)){
			$this->success('状态更新成功');
		}else{
			$this->error('状态更新失败');
		}
	}
	
	public function chuli(){
		$this->info = $this->m->where(array('id'=>I('id')))->relation(true)->find();
// 		dump($this->info);
		$this->display();
	}
	
	public function chuli_post(){
		if(IS_POST){
			if($_POST['id']){
				$_POST['update_time'] = Date('Y-m-d H:i:s');
				if($this->m->create()){
					if($this->m->save()){
						$this->success('更新成功');
					}else{
						$this->error('更新失败');
					}
				}
			}else{
				$this->error('更新失败');
			}	
		}
	}
}